package com.sibrary.booxoo.download;

public class BooxooDownloadItem {

	private String mUrl;
	private String mFilename;

	private int mProgress; // 下载进度

	private boolean mFinished; // 是否下载完成
	private boolean mCancel; // 表明是否为取消下载项

	public BooxooDownloadRunnable mRunnable; // 控制线程中的一些数据的, 每一个下载项对应一个线程
	
	public BooxooDownloadItem(final String url) {
		mUrl = url;
		mFilename = mUrl.substring(mUrl.lastIndexOf("/") + 1);
		checkFileName();

		mRunnable = null;
		mProgress = 0;
		

		mFinished = false;
		mCancel = false;		
	}

	public BooxooDownloadItem() {
		mUrl = null;
		mFilename = null;

		mRunnable = null;
		mProgress = 0;

		mFinished = false;
		mCancel = false;		
	}

	/**
	 * 检查文件名
	 */
	private void checkFileName() {
		int queryParamStart = mFilename.indexOf("?");
		if (queryParamStart > 0) {
			mFilename = mFilename.substring(0, queryParamStart);
		}
	}

	public void setUrl(String url) {
		mUrl = url;
	}

	public String getUrl() {
		return mUrl;
	}

	public void setFilename(String filename) {
		mFilename = filename;
	}

	public String getFilename() {
		return mFilename;
	}

	public void setProgress(int progress) {
		mProgress = progress;
	}

	public int getProgress() {
		return mProgress;
	}

	public boolean isAbort() {
		return false;
	}

	public void abort() {
		if (mRunnable != null) {
			mRunnable.AbortRunnable();
		}
	}

	public String getDownloadCancel() {
		if (mCancel) {
			return new String("true");
		} else {
			return new String("false");
		}
	}

	public void setDownloadCancel(String cancel) {
		if (cancel.equals("true")) {
			mCancel = true;
		} else {
			mCancel = false;
		}
	}

	public boolean getCancel() {
		return mCancel;
	}

	public void setCancel(boolean cancel) {
		mCancel = cancel;
	}
	
	public void setFinished(boolean finished) {
		mFinished = finished;
	}
	
	public boolean getFinished() {
		return mFinished;
	}
}
